home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-29 | 2.1 KB | 66 lines | [TEXT/CWIE] |
- // TreeNode.h
-
- #pragma once
-
- class TreeNode
- {
- protected:
- TreeNode *fParent;
- TreeNode *fLeftChild;
- TreeNode *fRightChild;
-
- void* fNodeKey;
- void* fNodeData;
-
- long fLeftChildCount;
- long fRightChildCount;
-
- public:
- // Start with the standard constructors an destructors
- TreeNode(void* theKey);
- TreeNode(void* theKey, void* theData);
- virtual ~TreeNode(void);
-
- // Create and insert an new node into the tree
- virtual TreeNode* InsertNode(void* theKey, void* theData);
-
- // Accessor functions for the keys and data in this tree
- // Note that you can't change the key, since it is unique and
- // that might cause a duplicate to appear. You should delete this
- // node, then re-add the data with the new key.
- virtual void* GetNodeKey(void);
- virtual void* GetNodeData(void);
- virtual void SetNodeData(void* theData);
-
- // Search functions for the tree
- virtual TreeNode* FindKeyNode(void* searchKey);
- virtual TreeNode* FindDataNode(void* searchData); // Returns FIRST instance of searchData
-
- // Miscellaneous information methods
- virtual long GetChildCount(void);
- long GetLeftChildCount(void); // Rarely called by object user
- long GetRightChildCount(void); // ditto
-
- // Methods for walking the tree
- virtual TreeNode* GetRoot(void);
- virtual TreeNode* GetFirstNode(void); // The first node in-order
-
- virtual TreeNode* GetNextNode(void); // Get the next node AFTER this node in-order
- virtual TreeNode* GetPreviousNode(void); // Get the previous node BEFORE this node
-
- // Utility function to remove an entire sub-tree
- virtual void PruneBranch(void); // Remove this branch and sub-branches from the tree.
-
- protected:
- virtual TreeNode* GetLeftmostSubNode(void); // For internal tree walking
- virtual void InsertChildLeft(TreeNode *nodePtr);
- virtual void InsertChildRight(TreeNode *nodePtr);
-
- virtual void DeleteChildLeft();
- virtual void DeleteChildRight();
-
- // Returns -1 if compareData < fNodeData, 0 if equal, and 1 if compareData > fNodeData
- virtual short CompareToNodeKey(void* compareKey);
- virtual short CompareToNodeData(void* compareData);
- };
-